package com.lisx.module_time_block.adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.lisx.module_time_block.bean.WeekBean;
import com.lisx.module_time_block.databinding.ItemWeekBinding;

import java.util.List;

public class WeekAdapter extends RecyclerView.Adapter<WeekAdapter.MyViewHolder> {

    List<WeekBean> weekData;

    public WeekAdapter(List<WeekBean> weekData) {
        this.weekData = weekData;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemWeekBinding binding = ItemWeekBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new MyViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        WeekBean weekBean = weekData.get(position);
        holder.binding.tvWeek.setText(weekBean.week);
        holder.binding.tvWeek.setSelected(weekBean.isSelect);
        holder.binding.container.setEnabled(weekBean.isWeek);
    }

    @Override
    public int getItemCount() {
        return weekData.size();
    }

    public void setData(List<WeekBean> weekData) {
        this.weekData = weekData;
        notifyDataSetChanged();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        private final ItemWeekBinding binding;

        public MyViewHolder(@NonNull ItemWeekBinding itemView) {
            super(itemView.getRoot());
            binding = itemView;
        }
    }
}
